<?php

namespace services\marketing;

use Yii;
use common\components\Service;
use common\models\marketing\TagsGroup;

/**
 * Class TagsGroupService
 * @package services\marketing
 */
class TagsGroupService extends Service
{
    /**
     * 根据ID查找信息
     *
     * @param int $id
     * @return TagsGroup|null
     */
    public function findById(int $id = 0): ?TagsGroup
    {
        return TagsGroup::find()->where(['id' => $id])->one();
    }

    /**
     * 查找信息
     *
     * @param array $condition
     * @return TagsGroup|null
     */
    public function findInfo(array $condition = []): ?TagsGroup
    {
        $query = TagsGroup::find();

//        isset($condition['project_id']) && $query->andWhere(['project_id' => $condition['project_id']]);
//        isset($condition['name']) && $query->andWhere(['name' => $condition['name']]);
//        isset($condition['status']) && $query->andWhere(['status' => $condition['status']]);

        return $query->one();
    }

    /**
     * 查找列表
     *
     * @param array $condition
     * @return array|\yii\db\ActiveRecord[]
     */
    public function findList(array $condition = [])
    {
        $query = TagsGroup::find();

        // select
        isset($condition['select']) && $query->select($condition['select']);

        // condition
        isset($condition['id']) && $query->andWhere(['id' => $condition['id']]);
        isset($condition['status']) && $query->andWhere(['status' => $condition['status']]);

        return $query->asArray()->all();
    }
}